package printer.impl;

import java.util.Set;
import java.util.TreeSet;

import pojo.Customer;
import printer.DataPrinter;

import comparetor.CustomerComparetorByBirth;

public class DataPrinterImpl implements DataPrinter {

	public StringBuilder print(Set<Customer> set, String format) {
		if("xml".equals(format)){
			return printXML(set);
		}
		else if("list".equals(format)){
			return printList(set);
		}
		
		return null;
	}
	
	public static StringBuilder printList(Set<Customer> set){
		StringBuilder sb = new StringBuilder("id\tname\tmail\t\t\tsex\tbirthday\n");
		for(Customer i: set){
			sb.append(i.toString());
		}
		return sb;
	}
	//127.0.0.1 8889
	public static StringBuilder printXML(Set<Customer> set){
		StringBuilder str = new StringBuilder("<Customers>\n");
		for(Customer i:set){
			str.append("\t<Customer id=\"" + i.getId() + "\">\n");
			str.append("\t\t<name>" + i.getName() + "<name>\n");
			str.append("\t\t<birth>" + i.getBirthday() + "</birth>\n");
			str.append("\t\t<mail>" + i.getMail() + "</mail>\n");
			str.append("\t\t<sex>" + i.getSex() + "</sex>\n");
		}
		str.append("\t</Customer>\n");
		str.append("</Customers>\n");
		return str;
	}

}
